package com.atguigu.userprofile.dao;

import com.atguigu.userprofile.bean.TagInfo;
import com.atguigu.userprofile.util.MysqlUtil;

import java.util.List;

/**
 * 负责tag_info表数据的增删改查操作
 */
public class TagInfoDao {

    /**
     * 查询所有被计算的标签
     *
     * 条件: 标签有对应的计算任务，且任务的状态为启用
     */
    public static List<TagInfo> selectTagInfosWithTaskStatusEnable(){
        String querySql = " select ti.id , ti.tag_code ,ti.tag_name , ti.tag_level , ti.parent_tag_id , ti.tag_type , " +
                " ti.tag_value_type ,ti.tag_value_limit , ti.tag_value_step , ti.tag_task_id , ti.tag_comment , ti.update_time ," +
                " ti.create_time " +
                " from tag_info ti join task_info tk " +
                " on ti.tag_task_id = tk.id " +
                " where tk.task_status = '1' ";
        List<TagInfo> tagInfos = MysqlUtil.queryList(querySql, TagInfo.class, true);
        return tagInfos ;
    }



    /**
     * 通过taskId查询TagInfo
     */
    public static TagInfo selectTagInfoByTaskId( String taskId ){
        String querySql = "select id , tag_code , tag_name , tag_level , parent_tag_id , tag_type , " +
                " tag_value_type , tag_value_limit , tag_value_step , tag_task_id , tag_comment , " +
                " update_time , create_time from tag_info  where tag_task_id = " + taskId ;
        TagInfo tagInfo = MysqlUtil.queryOne(querySql, TagInfo.class, true);
        return tagInfo ;
    }

    public static void main(String[] args) {
        List<TagInfo> tagInfos = selectTagInfosWithTaskStatusEnable();
        System.out.println(tagInfos);
    }
}
